cmake_minimum_required(VERSION 3.16)

project(attendenceSever VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


# 设置Qt路径
set(CMAKE_PREFIX_PATH "E:/downloads/code/QT/6.8.3/mingw_64" ${CMAKE_PREFIX_PATH})
set(Qt6_DIR "E:/downloads/code/QT/6.8.3/mingw_64/lib/cmake/Qt6")

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network Sql)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network Sql)

set(PROJECT_SOURCES
        main.cpp
        attendencewin.cpp
        attendencewin.h
        attendencewin.ui
        qfaceobject.cpp
        qfaceobject.h
        registerwin.h 
        registerwin.cpp 
        registerwin.ui
        select.h 
        select.cpp 
        select.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(attendenceSever
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET attendenceSever APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(attendenceSever SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(attendenceSever
            ${PROJECT_SOURCES}
        )
    endif()
endif()

# 添加头文件目录
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    "E:/code/Qtproject/package/opencv452/include"
    "E:/code/Qtproject/package/opencv452/include/opencv2"
    "E:/code/Qtproject/package/SeetaFace/include"
    "E:/code/Qtproject/package/SeetaFace/include/seeta"
)

# 添加库文件目录
link_directories(
    "E:/code/Qtproject/package/opencv452/x64/mingw/lib"
    "E:/code/Qtproject/package/SeetaFace/lib"
)

# 查找所有OpenCV和SeetaFace库文件
file(GLOB OPENCV_LIBS
    "E:/code/Qtproject/package/opencv452/x64/mingw/lib/libopencv_*.dll.a"
    "E:/code/Qtproject/package/opencv452/x64/mingw/lib/libopencv_*.a"
    "E:/code/Qtproject/package/opencv452/x64/mingw/lib/libopencv_*.lib"
)
file(GLOB SEETAFACE_LIBS
    "E:/code/Qtproject/package/SeetaFace/lib/libSeeta*.dll.a"
    "E:/code/Qtproject/package/SeetaFace/lib/libSeeta*.a"
    "E:/code/Qtproject/package/SeetaFace/lib/libSeeta*.lib"
)

# 链接库文件
target_link_libraries(attendenceSever PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Network
    Qt${QT_VERSION_MAJOR}::Sql
    # OpenCV库
    ${OPENCV_LIBS}
    # SeetaFace库
    ${SEETAFACE_LIBS}
)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.attendenceSever)
endif()
# set_target_properties(attendenceSever PROPERTIES
#     ${BUNDLE_ID_OPTION}
#     MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
#     MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
#     MACOSX_BUNDLE TRUE
#     WIN32_EXECUTABLE TRUE
# )

set_target_properties(attendenceSever PROPERTIES
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE FALSE  # 这里必须是FALSE
)

include(GNUInstallDirs)
install(TARGETS attendenceSever
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(attendenceSever)
endif()
